import { Component, OnInit,EventEmitter, Output } from '@angular/core';
import {BizfileService} from '../../../../../@core/service/case-review/doc-service/api/bizfile.service'
import { ClueDataService } from "../../../../../@core/service/clue-service/clue-data.service";
import * as moment from 'moment';
@Component({
  selector: 'app-termination-report',
  templateUrl: './termination-report.component.html',
  styleUrls: ['./termination-report.component.scss']
})
export class TerminationReportComponent implements OnInit {
  @Output('loadSpin') loadSpin = new EventEmitter();

  //加载动画
  public loading:boolean = false;
    //docid 如果是修改会传入docid
    public docid:string;
    BizFile: any;
    public sortValue: string = "0";
      //type选中值
  public treeValue: any;
      // 时间
  private date:any = new Date();
    //区域数据
    public areaData: any;
  public isReadonly:boolean = false;
  public getSelectValue:string;
  private _caseDate1:any = this.date;
  private _caseDate2:any = this.date;
      //form内容
  public formJson: any = {
    cY1:this.date.getFullYear(),
    cM1 : this.date.getMonth()+1,
    cD1 : this.date.getDate(),
    cY2:this.date.getFullYear(),
    cM2 : this.date.getMonth()+1,
    cD2 : this.date.getDate(),
    fiYear:this.date.getFullYear(),
    fiMon:this.date.getMonth()+1,
    fiDay:this.date.getDate()
  };

  public get caseDate1(){
    return this._caseDate1
  }
  public set caseDate1(val){
    if(val){
      let date:Date = new Date(val);
      this.formJson.cY1 = date.getFullYear();
      this.formJson.cM1 = date.getMonth()+1;
      this.formJson.cD1 = date.getDate();
    }
    this._caseDate1=val;
}
public get caseDate2(){
  return this._caseDate2
}
public set caseDate2(val){
  if(val){
    let date:Date = new Date(val);
    this.formJson.cY2 = date.getFullYear();
    this.formJson.cM2 = date.getMonth()+1;
    this.formJson.cD2 = date.getDate();
  }
  this._caseDate2=val;
}
constructor(
  public bizService:BizfileService,
  public clueData: ClueDataService,
  ) {
    this.areaData = clueData.area;
   }
  ngOnInit() {
    if(this.docid){ 
      this.bizService.queryBizFileByDocid(this.docid).subscribe(({data}:any)=>{
        this.loadSpin.emit(false);
        if(data){
          if(data.stage) this.getSelectValue = data.stage;
          this.BizFile = data;
          this.formJson = JSON.parse(data.formJson);
          this.caseDate1 = this.formJson.cY1+'-'+this.formJson.cM1+'-'+this.formJson.cD1;
          this.caseDate2 = this.formJson.cY2+'-'+this.formJson.cM2+'-'+this.formJson.cD2;
          if(this.formJson.caseType){
            this.treeValue = JSON.parse(this.formJson.caseType);
          }
          if(this.formJson.fontName||this.formJson.name||this.formJson.idNum){
            this.sortValue = '1';
          }
        }
      })
  }else{
      
  }
  }
  selectChange(event){
    this.getSelectValue = event;
  }
}
